<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="异常类型" prop="exceptionType">
        <el-select v-model="queryParams.exceptionType" placeholder="请选择异常类型">
          <el-option label="物料异常" :value=0></el-option>
          <el-option label="设备异常" :value=1></el-option>
          <el-option label="质量异常" :value=2></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="生产工单编号" prop="workorderCode">
        <el-input v-model="queryParams.workorderCode" placeholder="请输入生产工单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工序名称" prop="processName">
        <el-input v-model="queryParams.processName" placeholder="请输入工序名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工序编码" prop="processCode">
        <el-input v-model="queryParams.processCode" placeholder="请输入工序编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品编码" prop="itemCode">
        <el-input v-model="queryParams.itemCode" placeholder="请输入产品编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="itemName">
        <el-input v-model="queryParams.itemName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工位编码" prop="workstationCode">
        <el-input v-model="queryParams.workstationCode" placeholder="请输入工位编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="规格型号" prop="specification">
        <el-input v-model="queryParams.specification" placeholder="请输入规格型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="submitList" height="calc(100vh - 290px)">
      <el-table-column label="序号" align="center" width="50px">
        <template slot-scope="scope">
          <span>{{scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="工单编号" align="center" prop="workorderCode" />
      <el-table-column label="SN码" align="center" prop="snCode" />
      <el-table-column label="异常类型" align="center" prop="exceptionTypeName" />
      <el-table-column label="异常描述" align="center" prop="exceptionDescription" />
      <el-table-column label="告警时间" align="center" prop="createTime" />
      <el-table-column label="恢复时间" align="center" prop="unlockTime" />
      <el-table-column label="车间名称" align="center" prop="workshopName" />
      <el-table-column label="产线名称" align="center" prop="lineName" />
      <el-table-column label="工位编号" align="center" prop="workstationCode" />
      <el-table-column label="工序编码" align="center" prop="processCode" />
      <el-table-column label="工序名称" align="center" prop="processName" />
      <el-table-column label="产品编码" align="center" prop="itemCode" />
      <el-table-column label="产品名称" align="center" prop="itemName" />
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

  </div>
</template>

<script>
import { listSubmit, getSubmit, addSubmit } from "@/api/mes/pro/exceptionSubmit";

export default {
  name: "ExceptionWorkorder",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 异常反馈表格数据
      submitList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        exceptionId: null,
        exceptionType: null,
        workorderCode: null,
        processName: null,
        processCode: null,
        itemCode: null,
        itemName: null,
        workstationCode: null,
        specification: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询异常反馈列表 */
    getList() {
      this.loading = true;
      listSubmit(this.queryParams).then(response => {
        this.submitList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


    /** 导出按钮操作 */
    handleExport() {
      this.download('/mes/pro/exception/submit/export', {
        ...this.queryParams
      }, `exceptionSubmit_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
